(function () {
    var backtotop = document.getElementById('backtotop');
    var timer;
    backtotop.onclick = function () {
        // 设表先关 防止定时器冲突
        clearInterval(timer);
        // 设置定时器
        timer = setInterval(function () {
            document.documentElement.scrollTop -=100;
            if (document.documentElement.scrollTop <=0) {
                clearInterval(timer);
            }
        });

        // 监听页面的滚动
        window.onscroll = function () {
            // 卷动值
            var scrollTop = document.documentElement.scrollTop || window.scrollY;
            // 页面没有卷动，返回顶部按钮隐藏掉
            if (scrollTop == 0) {
                backtotop.style.display = 'none';
            } else {
                backtotop.style.display = 'block';
            }
        }
    }
})();